<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>查看设备</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="shortcut icon" href="#"/>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
		<span class="layui-breadcrumb">
			<a> <cite>设备列表</cite></a>
		</span>
    <a class="layui-btn layui-btn-small"
       style="line-height: 1.6em; margin-top: 3px; float: right"
       onclick="location.reload()" title="刷新"> <i
            class="layui-icon layui-icon-refresh" style="line-height: 30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <input type="hidden" name="id" id="id">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="设备名称" name="name" id="name">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <select name="equipmentType" id="equipmentType">
                                <option value="0">请选择设备类型</option>
                            </select>
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body">
                    <table id="projectList" lay-filter="projectList"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarList">
    <div class="layui-btn-container" >
        <button class="layui-btn layui-btn-sm" lay-event="add" id="add">
            <i class="layui-icon">&#xe654;</i>
            新增设备
        </button>
    </div>
</script>


<script>
    layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        var user = JSON.parse(window.sessionStorage.getItem("user"));
        var id = user.id;
        $("#id").prop("value", id);
        form.render();
        $.get('equipmentType', function (data) {
            var list = data.data;
            $.each(list, function (index, d) {
                $("#equipmentType").append(new Option(d.typeName, d.id));
            })
            form.render();
        });
        //项目列表
        var tableIns = table.render({
            elem: '#projectList',
            url: 'equipmentSearch',
            cellMinWidth: 95,
            page: true,
            height: "full-125",
            where: {"id": id},
            limit: 10,
            limits: [10, 15, 20, 25],
            id: "projectListTable",
            toolbar: "#toolbarList",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                /*{field: 'id', title: '编号', width: 60, align: "center"},*/
                {field: 'eno', title: '设备编码', align: 'center'},
                {field: 'name', title: '设备名称', align: 'center'},
                /*{field: 'barCode', title: '设备二维码图片地址', align: 'center'},*/
                {field: 'createdate', title: '创建时间', align: 'center'},
                {field: 'status', title: '状态', align: 'center',templet:function (data) {
                        if (data.status == 0){
                            return "已停用";
                        }
                        return "运行中";
                    }},
                /*{field: 'xiumanId', title: '默认维护人', align: 'center'},*/
                /*{field: 'equipmenttypeid', title: '设备类型编号', align: 'center'},*/
                {field: 'unitid', title: '属于单位号', align: 'center'},
                {field: 'pos', title: '设备位置', align: 'center'},
                {
                    title: '操作', minWidth: 470,  align: "center", templet: function (data) {
                        var str = " <a class='layui-btn ' lay-event='edit'>修改信息</a>";
                        str+= "<a class='layui-btn ' lay-event='addpic'>添加图片</a>";
                        str+= "<a class='layui-btn ' lay-event='qrcode'>生成二维码</a>";
                        if (data.status == 0){
                            str+="<a class='layui-btn '  lay-event='change'>启用</a>";
                            str+="<a class='layui-btn '  lay-event='repair'>报修</a>";
                        }
                        if (data.status == 1){
                            str+="<a class='layui-btn '  lay-event='change'>停用</a>";
                        }
                        str+= "<a class='layui-btn '  lay-event='repairRecord'>查看维修记录</a>";
                        return str ;
                    }
                }
            ]]
        });


        //搜索【此功能需要后台配合】
        form.on("submit(sreach)", function (data) {
            table.reload("projectListTable", {
                page: {
                    curr: 1
                    //重新从第 1 页开始
                },
                where: {
                    name: $("input[name=name]").val(), //搜索的关键字
                    equipmentType: $("select[name=equipmentType]").val(),
                }
            });
            return false;
        });



        //添加设备
        $("#add").click(function () {
            xadmin.open('添加设备', './baoxiumanAddEquipment.html', 800, 500);
        });
        //列表操作
        table.on('tool(projectList)', function (obj) {
            var $ = layui.$;
            var layEvent = obj.event;
            switch (layEvent) {
                case "edit":
                    xadmin.open('修改设备信息', './equipmentUpdate.html?' + obj.data.id, 600, 400);
                    break;
                case "change":
                    $.get("changeStatus", {id: obj.data.id, status: obj.data.status}, function (p) {
                        if (p.code != 0) {
                            layer.alert("异常");
                            return;
                        }
                        if (obj.data.status == 1) {
                            layer.alert("设备已停止工作");
                            tableIns.reload();
                        }
                        if (obj.data.status == 0) {
                            layer.alert("设备已开始运行");
                            tableIns.reload();
                        }
                    })
                    break;
                case "qrcode":
                    $.get("addQrcode",{id:obj.data.id},function (p) {
                        if(p.code == 0){
                            xadmin.open('设备二维码', './equipment_qrcode.html?' + obj.data.id, 340, 400);
                        }
                    });
                    break;
                case "addpic":
                    xadmin.open('添加图片', './baoxiumanAddEQPic.html?' + obj.data.id, 800, 500);
                    break;
                case "repair":
                    xadmin.open('报修', './baoxiumanAddbaoxiudan.html?' + obj.data.id, 800, 500);
                    break;
                case "repairRecord":
                    xadmin.open('查看维修记录', './baoxiumanEqBxds.html?' + obj.data.id, 600, 400);
                    break;
            }
        });
    })
</script>

</html>